<!-- 产品样式组件 -->
<template>
  <div class="product-item">
    <img :src="product.imgUrl" class="item-img">
    <div class="item-content">
      <div class="item-content-name">{{ product.name }}</div>
      <div class="item-content-sale">月售{{ product.sales }}件</div>
      <div class="item-content-info">
        <div class="price">￥{{ product.price }}</div>
        <div class="oldPrice">￥{{ product.oldPrice }}</div>
        <div class="sub" v-if="product.count">
          <div class="sub-btn" @click="handleSub(product)">-</div>
          <div class="sub-count">{{product.count}}</div>
        </div>
        <div class="add" @click="handleAdd(product)">+</div>
      </div>
    </div>
  </div>
</template>

<script>
import { toRefs } from 'vue';
import { useStore } from 'vuex'
// 添加、删除商品
export const useAddSub = (shopId,store) => {
  const handleAdd = product => {
    store.commit('add',{product,shopId});
  }
  const handleSub = product => {
    store.commit('sub',{product,shopId});
  }
  return {handleAdd,handleSub}
}
// composition
export default {
  name:'detailProduct',
  props:['product','shopId'],
  setup(props){
    const store = useStore();
    const {shopId} = toRefs(props)
    const {handleAdd,handleSub} = useAddSub(shopId.value,store)
    return {handleAdd,handleSub}
  }
}
</script>

<style scoped lang="scss">
@import '@/styles/theme.scss';
@import '@/styles/mixin.scss';
.product-item{
  height: 21.3333vw;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f1f1f1;
  .item-img{
    width: 18.1333vw;
    height: 18.1333vw;
    margin-right: 16px;
  }
  &+.product-item{
    margin-top: 12px;
  }
  .item-content{
    &-sale{
      font-size: 12px;
      color: $theme-font-color;
      margin-bottom: 2.5vw;
    }
    @include content-name;
    &-info{
      @include content-info;
      @include add-sub-btn;
    }
  }
}
</style>
